package com.android.commcount.ui.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.android.baselibrary.util.DateUtil;
import com.android.commcount.R;
import com.android.commcount.bean.Count_DetailInfo;

public class CommCount_CountView extends LinearLayout {

    Context context;

    public CommCount_CountView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initView(attrs);
    }

    public CommCount_CountView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView(attrs);
    }

    LinearLayout  ll_all_length;
    TextView tv_count, tv_length, tv_all_length ;

    private void initView(AttributeSet attrs) {
        View.inflate(context, R.layout.view_commcount_count, this);
        ll_all_length = findViewById(R.id.ll_all_length);

        tv_count = findViewById(R.id.tv_count);
        tv_length = findViewById(R.id.tv_length);
        tv_all_length = findViewById(R.id.tv_all_length);

    }

    public void setData(Count_DetailInfo info) {
        tv_count.setText(info.count + "");
        if (info.length == 0) {
            tv_length.setText("根");
            ll_all_length.setVisibility(GONE);
        } else {
            tv_length.setText("根/" + info.length + "米");
            ll_all_length.setVisibility(VISIBLE);
            double allLength = com.android.commcount.util.Util.jisuanDouble(info.length, info.count);
            tv_all_length.setText(allLength + "米");
        }
    }
}
